package com.sparrow.gate.rest;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/test")     // 通过这里配置使下面的映射都在/users下
public class UserControllerTest
{

    @RequestMapping("/get-user")
    @Cacheable(value = "user-key", keyGenerator = "wiselyKeyGenerator")
    public User getUser()
    {
        User user = new User();
        user.setId(1L);
        user.setAge(0);
        user.setName(String.valueOf(Math.random()));
        System.out.println("若下面没出现“无缓存的时候调用”字样且能打印出数据表示测试成功");
        return user;
    }

    @RequestMapping("/get-user2")
    @Cacheable(value = "user-key", keyGenerator = "wiselyKeyGenerator")
    public User getUser2()
    {
        User user = new User();
        user.setId(2L);
        user.setAge(1);
        user.setName(String.valueOf(Math.random()));
        System.out.println("若下面没出现“无缓存的时候调用”字样且能打印出数据表示测试成功");
        return user;
    }
}
